package iterator

import "errors"

type tArrayStack struct {
	size int
	items []interface{}
}


func NewArrayStack() IArrayStack {
	return &tArrayStack{
		0,
		make([]interface{}, 0),
	}
}

func (me *tArrayStack) Size() int {
	return me.size
}

func (me *tArrayStack) Push(it interface{}) {
	me.items = append(me.items, it)
	me.size++
}

func (me *tArrayStack) Pop() (error, interface{}) {
	if me.size <= 0 {
		return errors.New("empty stack"), nil
	}

	last := me.items[me.size - 1]
	me.items = me.items[0:me.size-1]
	me.size--
	return nil,last
}

func (me *tArrayStack) Iterator() IIterator {
	return newArrayStackIterator(me)
}